/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.fei.ClassDiagram.Editor.Wrappers;

import java.util.Set;
import javax.lang.model.element.Modifier;
import org.fei.ClassDiagram.XMI.XmiTypePlaceHolder;
import org.netbeans.modules.classfile.Variable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 *
 * @author Tomas
 */
public class VariableDataWrapper extends BasicClassMemberWrapper {
        
    private Variable variable;
    private ClassDataWrapper asotioationType;   // ak ide o asociaciu, a je tohto typu
    
    public VariableDataWrapper(Variable variable) {
    
        super(variable);
        
        this.variable = variable;
        asotioationType = null;
    }
    
    public VariableDataWrapper(String name, String type, Set<Modifier> mods) {
        super(name, type, mods);
        
        variable = null;
        asotioationType = null;
    }

    public Element xmiCreateAttributeElement(Document document) {
    
        Element type = document.createElement("UML:StructuralFeature.type");
        
        Element attribute = document.createElement("UML:Attribute");
        
        attribute.setAttribute("xmi.id", this.xmiid);
        attribute.setAttribute("name", this.name);
        attribute.setAttribute("visibility", this.accessToFullString());
        attribute.setAttribute("isSpecification", "false");
        attribute.setAttribute("ownerScope", this.isStatic() ? "classifier" : "instance");
        
        if (asotioationType != null) {
            Element classElement = document.createElement("UML:Class");
            classElement.setAttribute("xmi.idref",  asotioationType.getXmiid());
            type.appendChild(classElement);
        }
        else {
            Element dataType = document.createElement("UML:DataType");
            dataType.setAttribute("xmi.idref", XmiTypePlaceHolder.getTypeId(this.returnType));
            type.appendChild(dataType);
        }

        attribute.appendChild(type);
         
        return attribute;
    }
    
    public Element xmiCreateEnumerationLiteralElement(Document document) {
    
        Element enumeration = document.createElement("UML:EnumerationLiteral");
        enumeration.setAttribute("xmi.id", this.xmiid);
        enumeration.setAttribute("name", this.name);
        enumeration.setAttribute("isSpecification", "false");
        
        return enumeration;
    }

    /**
     * @param asotioationType the asotioationType to set
     */
    public void setAsotioationType(ClassDataWrapper asotioationType) {
        this.asotioationType = asotioationType;
    }
}
